#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int N = 3e5 + 10;

vector<int> edges[N];
int in[N];
int n, m;

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int k; cin >> k;
		for(int j = 1; j <= k; j++)
		{
			int x; cin >> x;
			edges[x].push_back(i);
			in[i]++;
		}
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		for(auto t : edges[x])
		{
			in[t]--;
			if(in[t] == 0) cnt++;
			
		}
		cout << cnt << endl;
	}
	return 0;
}
